<table class="table table-hover">
    <thead>
        <tr>
            <th>发货单号</th>
            <th>批次号</th>
            <th>平台</th>
            <th>销售员</th>
            <th>目的仓库</th>
            <th>站点</th>
            <th>状态</th>
            <th>运输状态</th>
            <th>是否标贴</th>
            <th style="max-width: 200px;">备注</th>
            <th>发货时间</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @foreach($paginator as $row)
            <tr>
                <td>{{ $row->delivery_no ?? '' }}</td>
                <td>{{ $row->batch_no ?? '' }}</td>
                <td>{{ $row->plat->title ?? '' }}</td>
                <td>{{ \App\Util\User::getUsernameById($row->seller_id) }}</td>
                <td>{{ $row->warehouse->w_code ?? '' }}</td>
                <td>{{ $row->area->area ?? '' }}</td>
                <td>{{ \App\Models\OverSeasIn\Delivery::$_status[$row->status] }}</td>
                <td>
                    <a href="javascript:void(0)" class="list-modal" data-id="{{ $row->id }}" data-action="listCheckTransport">
                        {{ \App\Models\OverSeasIn\Delivery::$_transportStatus[$row->transport_status] }}
                    </a>
                </td>
                <td>{{ \App\Models\OverSeasIn\Delivery::$_isFnsku[$row->is_fnsku] ?? '' }}</td>
                <td>{{ $row->remarks }}</td>
                <td>{{ $row->delivered_at }}</td>
                <td>
                    @if(\Encore\Admin\Facades\Admin::user()->isRole('salesperson') && \Encore\Admin\Facades\Admin::user()->id != $row->seller_id)
                        @if(\Encore\Admin\Facades\Admin::user()->can('os-in.os'))
                            <a href="/xqc/overseas-in/os-dropshipping/{{ $row->id }}" class="btn btn-xs btn-primary">查看</a>
                        @endif
                    @else
                        @if(\Encore\Admin\Facades\Admin::user()->can('os-in.os'))
                            <a href="/xqc/overseas-in/os-dropshipping/{{ $row->id }}" class="btn btn-xs btn-primary">查看</a>
                        @endif
                        @if(\Encore\Admin\Facades\Admin::user()->can('os.edit'))
                            <a href="/xqc/overseas-in/os-dropshipping/{{ $row->id }}/edit" class="btn btn-xs btn-danger">编辑</a>
                        @endif
                        @if($row->status == 1)
                            {{--@if($row->is_fnsku == 1)--}}
                                <button class="btn btn-xs btn-info list-file-modal" data-id="{{ $row->id }}" data-action="listUploadLabels">上传标签</button>
                            {{--@endif--}}
                            <a href="javascript:void(0);" data-id="{{ $row->id }}" data-action="uploadedLabels" class="btn btn-xs btn-default grid-row-os">标签上传完成</a>
                        @endif
                        @if($row->status == 1 && \Encore\Admin\Facades\Admin::user()->can('os-in.os.delete'))
                            <a href="javascript:void(0);" data-id="{{ $row->id }}" class="btn btn-xs btn-danger os-del">删除</a>
                        @endif
                        @if(\Encore\Admin\Facades\Admin::user()->can('os-in.os.ship'))
                            @if($row->status == 2)
                                <button class="btn btn-xs btn-info list-modal" data-id="{{ $row->id }}" data-action="listStartPreparing">开始备货</button>
                            @elseif($row->status == 3)
                                <button class="btn btn-xs btn-info list-modal" data-id="{{ $row->id }}" data-action="listPreparing">备货</button>
                                <a href="javascript:void(0);" data-id="{{ $row->id }}" data-action="prepared" class="btn btn-xs btn-warning grid-row-os">备货完成</a>
                            @endif
                        @endif
                        @if($row->status == 4 && \Encore\Admin\Facades\Admin::user()->can('os-in.os.box'))
                            <a href="/xqc/overseas-in/os-dropshipping/{{ $row->id }}/box" class="btn btn-xs btn-info">录入装箱信息</a>
                        @endif
                        @if(in_array($row->status,[2,3,4,5]))
                            <a href="javascript:void(0);" data-id="{{ $row->id }}" class="btn btn-xs btn-default os-back">返回标签上传</a>
                        @endif
                        @if($row->status >= 4 && \Encore\Admin\Facades\Admin::user()->can('os-in.os.logistics'))
                            <button class="btn btn-xs btn-info list-logistics-modal" data-id="{{ $row->id }}" data-action="listLogistics">物流信息</button>
                            <button class="btn btn-xs btn-warning list-logistics-modal" data-id="{{ $row->id }}" data-action="listTransport">运输信息</button>
                        @endif
                        @if($row->status == 5 && \Encore\Admin\Facades\Admin::user()->can('os-in.os.ship'))
                            <a href="javascript:void(0);" data-id="{{ $row->id }}" data-action="ship" class="btn btn-xs btn-danger grid-row-os">发货</a>
                        @endif
                        @if($row->status > 4)
                            <a href="/xqc/overseas-in/os-dropshipping-box/{{ $row->id }}/download" target="_blank" class="btn btn-xs btn-default">导出装箱信息</a>
                        @endif
                        @if(\Encore\Admin\Facades\Admin::user()->can('os.download'))
                            <a href="/xqc/overseas-in/os-dropshipping/{{ $row->id }}/download" target="_blank" class="btn btn-xs btn-default">下载</a>
                        @endif
                    @endif

                    @if(!empty($row->logistics->tracking_no))
                        <a href="/xqc/overseas-in/os/{{ $row->id }}/download-tracking-no" target="_blank" class="btn btn-xs btn-default">下载物流单号</a>
                    @endif
                </td>
            </tr>
        @endforeach
    </tbody>
</table>
<!--上传文件Modal -->
<div class="modal fade" id="listFileModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- 内容会加载到这里 -->
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!--操作预览Modal -->
<div class="modal fade" id="listModal" tabindex="-1" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog" style="width: 60%;">
        <div class="modal-content">
            <!-- 内容会加载到这里 -->
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!--更新物流Modal -->
<div class="modal fade" id="listLogisticsModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- 内容会加载到这里 -->
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script language="JavaScript" type="text/javascript">
    $(function () {
        var _ajax = function (action,param) {
            $.ajax({
                method: 'post',
                url: '/xqc/overseas-in/os-dropshipping-ajax',
                data: {
                    _token: "{{ csrf_token() }}",
                    action:action,
                    param:param
                },
                success: function (data) {
                    if (typeof data === 'object') {
                        if (data.status) {
                            toastr.success('提交成功 !');
                            $.pjax.reload('#pjax-container');
                        } else {
                            swal(data.message, '', 'error');
                        }
                    }
                }
            });
        };
        var _ajaxConfirm = function(action,param,resolve){
            $.ajax({
                method: 'post',
                url: '/xqc/overseas-in/os-dropshipping-ajax',
                data: {
                    _token: "{{ csrf_token() }}",
                    action: action,
                    param: param
                },
                success: function (data) {
                    resolve(data);
                }
            });
        };
        //上传文件Modal
        $('.list-file-modal').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            var action = $(this).data('action');
            $("#listFileModal").modal({
                remote : '/xqc/overseas-in/os-dropshipping-modal?action=' + action + '&param=' + id
            });
        });
        $("#listFileModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        });

        //更新物流
        $('.list-logistics-modal').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            var action = $(this).data('action');
            $("#listLogisticsModal").modal({
                remote : '/xqc/overseas-in/os-dropshipping-modal?action=' + action + '&param=' + id
            });
        });
        $("#listLogisticsModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        });

        //操作预览Modal
        $('.list-modal').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            var action = $(this).data('action');
            $("#listModal").modal({
                remote : '/xqc/overseas-in/os-dropshipping-modal?action=' + action + '&param=' + id
            });
        });
        $("#listModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        });
        //删除
        $('.os-del').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            swal({
                title: "确定删除？",
                text : "确定要删除此单吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        _ajaxConfirm('osDel',id,resolve)
                    });
                }
            }).then(function(result) {
                var data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        toastr.success('提交成功 !');
                        $.pjax.reload('#pjax-container');
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });
        //返回标签上传
        $('.os-back').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            swal({
                title: "确定返回？",
                text : "确定要返回上传标签吗？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                showLoaderOnConfirm: true,
                cancelButtonText: "取消",
                preConfirm: function() {
                    return new Promise(function(resolve) {
                        _ajaxConfirm('backUploadLabels',id,resolve)
                    });
                }
            }).then(function(result) {
                var data = result.value;
                if (typeof data === 'object') {
                    if (data.status) {
                        toastr.success('提交成功 !');
                        $.pjax.reload('#pjax-container');
                    } else {
                        swal(data.message, '', 'error');
                    }
                }
            });
        });

        //发货，备货完成，标签上传完成
        $('.grid-row-os').unbind('click').click(function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            var action = $(this).data('action');
            _ajax(action,id);
        });
    });
</script>
